<?php
/**
 * Created by PhpStorm.
 * 加盟商控制器
 * User: lyb
 * Date: 2017/1/11
 * Time: 10:18
 */

class FranchiseesOrder extends MY_Controller{
    function __construct()
    {
        parent::__construct();
        $this->load->model('franchisees_model');
    }
    public function orderList(){
        if($this->users['franchisees_id'] || $this->users['role_id']) {
            $gp = gp();
            $gp['page'] = $gp['page'] ? $gp['page'] : 1;
            $str = "?keyword=" . $gp['keyword'] . "&available=" . $gp['available'] . "&pid=" . $gp['pid'] . "&status_id=" . $gp['status_id'];
            //分页查询
            $this->load->library('pagination');
            $config['page_query_string'] = TRUE;
            $config['base_url'] = blang_url('orders/FranchiseesOrder/orderList' . $str);
            $config['uri_segment'] = config_item('enable_lang') ? 5 : 4;
            $config['per_page'] = 20;
            $orderList = $this->franchisees_model->getFranchiseesOrder($this->users['role_id'],$this->users['franchisees_id'], trim($gp['keyword']), $gp['available'], $gp['pid'], $gp['status_id'],($gp['page'] - 1) * $config['per_page'], $config['per_page']);
            $config['total_rows'] = $this->franchisees_model->countNum($this->users['role_id'],$this->users['franchisees_id'], trim($gp['keyword']), $gp['available'], $gp['pid'], $gp['status_id']);
            $this->pagination->initialize($config);
            $data['show_pages'] = $this->pagination->create_links();
            //分页结束
            //重构数据
            foreach ($orderList as $key => &$rs) {
                $serviceType = $this->common_model->selectFirst('mt_service_type', array('id' => $rs['service_type']));
                $categoryFirst = $this->common_model->selectFirst('mt_product_category', array('id' => $rs['category_id']));
                $statusFirst = $this->common_model->selectFirst('mt_product_status', array('id' => $rs['status_id']));
                $rs['serviceName'] = $serviceType['name_' . $this->curLang];
                $rs['categoryName'] = $categoryFirst['name_' . $this->curLang];
                $rs['statusName'] = $statusFirst['name_' . $this->curLang];
                $rs['add_time'] = 'updateDate:' . date('Y-m-d H:i:s', $rs['add_time']);
                $rs['holdColorOrder'] = $rs['orderAvailable'] == 2 ? '#ff0909' : '#0a8e61';
                $rs['holdColorProduct'] = $rs['available'] == 2 ? '#ff0909' : '#0a8e61';
                $rs['nextAct'] = $this->common_model->flowAction($rs['id'], $rs['status_id']);
                //追踪号规则
                $rs['isInTrackNum'] = true;
                if ($rs['status_id'] == 14 && $rs['shipoutTrack']) {
                    $rs['isInTrackNum'] = false;
                }
            }
            unset($rs);
            $statusList = $this->common_model->selectCustom('mt_product_status');
            $data['statusList'] = $statusList;
            $data['orderList'] = $orderList;
            $data['curLang'] = $this->curLang;
            $this->load->view('defaults/franchiseesOrder_list', $data);
            $this->load->view('defaults/common/footer');
        }else{
            js_goto('','你的账号尚未关联加盟商',1);
        }
    }
}